using System;
using Lichtspiel.Utility;

namespace Lichtspiel.ECSystem.Behaviors
{
    /// <summary>
    /// A Behavior that does nothing. Good for breakes in sequences.
    /// </summary>
    public class DoNothingFor : Behavior
    {
        private TimeSpan length;
        private Timer timer;

        public DoNothingFor(TimeSpan length) 
            : this(length, null) {}

        public DoNothingFor(TimeSpan length, Action finished)
            : base(finished) {
            this.length = length;
        }

        protected override void Initialize() {
            timer = new Timer(length, false, t => BehaviorFinished());
        }

        public override void Update(GameTime time) {
            base.Update(time);

            timer.Update(time);
        }

        internal override void Stop() {
            base.Stop();

            if (timer != null) {
                timer.Stop();
                timer = null;
            }
        }
    }
}